package kr.co.redcircle.service.oAuth.api.google;

import kr.co.redcircle.service.oAuth.service.DefaultGoogle20Api;
import kr.co.redcircle.service.oAuth.service.OAuthForGoogle20ServiceImpl;

import org.scribe.model.OAuthConfig;
import org.scribe.oauth.OAuthService;
import org.scribe.utils.Preconditions;

public class Google20Api extends DefaultGoogle20Api{
	
	private static final String AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/auth?client_id=%s&redirect_uri=%s&response_type=code&scope=%s&access_type=offline";

	public String getAccessTokenEndpoint() {
		return "https://accounts.google.com/o/oauth2/token";
	}

	public String getAuthorizationUrl(OAuthConfig config) {
		
		Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Google does not support OOB");
		return String.format(AUTHORIZE_URL, config.getApiKey(), config.getCallback(), config.getScope());
		
	}

	public OAuthService createService(OAuthConfig config) {
		
		return new OAuthForGoogle20ServiceImpl(this, config); 
	}	

}
